import xml.Pair;

import java.io.*;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: oye
 * Date: 07.11.11
 * Time: 15:11
 * To change this template use File | Settings | File Templates.
 */
public class eval_rte {

    public static double evaluateWordMatching(List<Pair> pairs, String predFileName) throws IOException {
        FileReader fReader = new FileReader(predFileName);
        BufferedReader reader = new BufferedReader(fReader);

        int numbCorrect = 0;
        if(reader.readLine().equals("ranked: no")){
            for(Pair p : pairs){
                if(p.getEntailment().equals(reader.readLine().split(" ")[1])){
                    numbCorrect++;
                }
            }
        }
        return (double)numbCorrect/(double)pairs.size();
    }

    public static double evaluateLemmaMatching(List<xmlpreprocessed.Pair> pairs, String predFileName) throws IOException {
        FileReader fReader = new FileReader(predFileName);
        BufferedReader reader = new BufferedReader(fReader);

        double countPairsInFile = 0;
        double numCorrect = 0;

        reader.readLine();
        while(reader.ready()) {

            String [] s =  reader.readLine().split(" ");
            for (xmlpreprocessed.Pair pair : pairs) {
                if(pair.getId() == Integer.parseInt(s[0])) {
                    if(pair.getEntailment().equals(s[1]))
                        numCorrect++;
                }
            }
           countPairsInFile++;
        }
        return (numCorrect/countPairsInFile)*100;
    }
}
